package com.yulebaby.callsenter.ui.view;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.yulebaby.callsenter.R;

/**
 * 退出对话框
 */
public class PromptDialog extends Dialog implements View.OnClickListener {


    private DialogCallBack callback;
    private Context context;
    private View mView;
    private String title;
    private String confirm;
    private String cancel;


    public PromptDialog(Context context, String title, String confirm, String cancel, DialogCallBack callback) {
        super(context, R.style.NoTitleDialogStyle);
        this.context = context;
        this.callback = callback;
        if (confirm == null || title == null || cancel == null) {
            throw new NullPointerException("提示信息不能为空");
        }
        this.title = title;
        this.confirm = confirm;
        this.cancel = cancel;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mView = LayoutInflater.from(context).inflate(R.layout.dialog_logout, null);
        TextView tv_info = (TextView) mView.findViewById(R.id.tv_dialoginfo);
        Button btn_confirm = (Button) mView.findViewById(R.id.btn_logout_confirm);
        Button btn_cancel = (Button) mView.findViewById(R.id.btn_logout_cancel);
        btn_confirm.setText(confirm);
        tv_info.setText(title);
        btn_cancel.setText(cancel);
        btn_confirm.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);
        setContentView(mView);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_logout_confirm:
                if (callback != null) {
                    callback.onConfirm();
                }
                break;
            case R.id.btn_logout_cancel:
                dismiss();
                break;
        }
    }

    public interface DialogCallBack {
        void onConfirm();
    }
}
